﻿/*----------------------------------------------------------------
//  <copyright file="MicroCloudCookieAuthenticationEvents.cs" company="MicroCloud@151504200868">
//      Copyright © 2020-2024 MicroCloud Corporation, All rights reserved.
//  </copyright>
//  <site>https://gitee.com/chenmm123/microclouds</site>
//  <last-editor>cmm</last-editor>
//  <last-date>2022-11-15 14:35</last-date>
//----------------------------------------------------------------*/

namespace MicroCloud.Authentication.Cookies
{
    #region "自定义 CookieAuthenticationEvents"
    /// <summary>
    /// 自定义 CookieAuthenticationEvents
    /// </summary>
    public class MicroCloudCookieAuthenticationEvents : CookieAuthenticationEvents
    {
        #region "方法"
        #region "Cookie验证通过时，从OnlineUser缓存或数据库查找用户的最新信息附加到有效的 ClaimIdentity 上"
        /// <summary>
        /// Cookie验证通过时，从OnlineUser缓存或数据库查找用户的最新信息附加到有效的 ClaimIdentity 上
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Task ValidatePrincipal(CookieValidatePrincipalContext context)
        {
            ClaimsPrincipal user = context.Principal;
            ClaimsIdentity identity = user.Identity as ClaimsIdentity;

            IUserClaimsProvider accessClaimsProvider = context.HttpContext.RequestServices.GetService<IUserClaimsProvider>();
            return accessClaimsProvider.RefreshIdentity(identity);
        }
        #endregion

        #endregion

    }
    #endregion

}
